<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<link rel="stylesheet" href="${aier_css_url}jc/chosen.css">
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>

<div class="top-bg">
	<img id="top-bg" src="" style="width: 100%;height: 100%">
	<div class="cover-setting">
		<a class="cover-setting-btn">封面设置</a>
		<!--  封面设置 -->
		<div class="window-el-cov-set" id="coverSetDialog" title="封面设置"
			style="display: none;">
			<div class="navbar">
				<ul class="float-list clearfix">
					<li class="classic-cover-btn current"><a>经典封面</a>
					</li>
					<li class="custom-cover-btn"><a>自定义</a>
					</li>
				</ul>
			</div>
			<div class="box">
				<!-- 经典封面 -->
				<div class="classic-cover-box open">
					<div class="select-area">
						<ul class="float-list clearfix">
							<li id="tha_0"><a href="javascript:void(0);"
								onclick="coLitog('0')"> <img
									src="${schoolimg_get_url}small/0.jpg" alt=""> <span>回忆</span>
							</a></li>

							<li id="tha_1"><a href="javascript:void(0);"
								onclick="coLitog('1')"> <img
									src="${schoolimg_get_url}small/1.jpg" alt=""> <span>一个人</span>
							</a></li>

							<li id="tha_2"><a href="javascript:void(0);"
								onclick="coLitog('2')"> <img
									src="${schoolimg_get_url}small/2.jpg" alt=""> <span>童年</span>
							</a></li>

							<li id="tha_3"><a href="javascript:void(0);"
								onclick="coLitog('3')"> <img
									src="${schoolimg_get_url}small/3.jpg" alt=""> <span>水果暴动</span>
							</a></li>

						</ul>
					</div>
				</div>

				<!-- 自定义 -->
				<div class="custom-cover-box">
					<div class="picture-preview-area">
						<img class="area-img" alt=""
							src="${aier_img_url}temp/userCovers/1.png" style="display: none;">
						<div id="reselect" onclick="delfile();" class="select-btn"
							style="cursor: pointer;display: none;">重新选择</div>
						<input class="input_opacity" type="file" id="file" name="file">
						<label id="upPic" class="select-btn" style="cursor:pointer;"
							for="file"><a class="select-btn" id="b_selfile"
							href="javascript:;">点击上传图片 </a> </label>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			var tagId = 0;
			function openTag() {
				if ($(this).hasClass('current')) {
					//do nothing
				} else {
					$(this).addClass('current').nextAll()
							.removeClass('current');
					$(this).prevAll().removeClass('current');
					$('.custom-cover-box,.classic-cover-box').removeClass(
							'open');
				}
				;
				if ($('.classic-cover-btn').hasClass('current')) {
					tagId = 0;
					$('.classic-cover-box').addClass('open');
				} else {
					tagId = 1;
					$('.custom-cover-box').addClass('open');
				}

			};

			$('.classic-cover-btn,.custom-cover-btn').click(openTag);

			$('#coverSetDialog')
					.dialog(
							{
								//背景变暗
								modal : true,
								autoOpen : false,
								show : "fade",
								hide : "fade",
								width : "650",
								buttons : {
									"确定" : function() {

										if (0 == tagId) {
											var fun = function(data) {
												loadCovers();
												$('#coverSetDialog').dialog(
														"close");
											};
											exeAjax(
													ajaxUrl("${aier_url}${aier_urijs}scomm_updateGivImgName${aier_suffix}"),
													fun, {
														"selCoId" : selCoId,
														"sid" : "${sid}"
													});

										} else if (1 == tagId) {
											var fun = function(data1) {
												loadCovers();
												$('#file').show();
												$('#upPic').show();
												$('.area-img').hide();
												$('#reselect').hide();
												$('#coverSetDialog').dialog(
														"close");
											};
											exeAjax(
													ajaxUrl("${aier_url}${aier_urijs}scomm_updateSImgName${aier_suffix}"),
													fun, {
														"sid" : "${sid}",
														"img" : imgName
													});
										}
									},
									"取消" : function() {
										$(this).dialog("close");
									}
								}
							});

			$('.cover-setting-btn').click(function() {
				$('#coverSetDialog').dialog('open');
			});
		</script>
	</div>
</div>

<div class="school-info">
	<!-- 右侧信息 -->
	<div class="school-info-main">
		<div class="school-info-name">
			<span>${school.name }</span>
		</div>
		<!-- 
		<div class="school-info-signature">
			学校简介：${school.desinfo }<a
				href="">更多</a>
		</div>
		 
		<div class="school-info-setting clearfix">
			<a class="btn-normal-orange"> <span>关注</span> </a>
		</div>-->
	</div>

	<!-- 头像 -->
	<div class="school-avatar">
		<div class="avatar">
			<img src="${schoollogo_get_url}big/${school.slogo }" alt="">
			<div class="manage">
				<a class="btn btn-schoolmanage btn-normal-orange "
					href="javascript:void(0);" onclick="goschoolM();"> <span>学校管理</span>
				</a> <a class="btn btn-normal-orange btn-dialog-join"
					href="javascript:void(0);"> <span>加入学校</span> </a>
			</div>
		</div>
		<!-- 粉丝关注微博数 -->
		<div class="school-avatar-bottom">
			<ul class="float-list clearfix">
				<li><a class="follow-num" href=""> <strong>${school.num_teacher
							}</strong> <span>教师</span> </a></li>
				<!--<li><a class="fan-num" href=""> <strong>${school.num_student
							}</strong> <span>学生</span> </a>
				</li>  -->
				<li><a class="xxs-num" href=""> <strong>${school.num_parent
							}</strong> <span>家长</span> </a></li>
			</ul>
		</div>
	</div>


	<!-- 申请加入学校弹出层-->
	<div class="dialog-joinschool" title="加入学校" id="joinSchool"
		style="display: none;">

		<div class="tabs">
			我的身份是: <a id="tabParent" class="current">家长</a> <a id="tabTeacher">教师</a>
		</div>

		<div class="forms">
			<div id="formParent">
				<div class="inputbar clearfix">
					<label for="nickname">孩子的姓名</label> <input id="nickname"
						name="nickname" type="text" class="PY-input">
				</div>
				<div class="selectbar clearfix">
					<label for="callName">您是孩子的</label> <select name="selectCallName"
						id="selectCallName" class="chosen">
						<option value="爸爸">爸爸</option>
						<option value="妈妈">妈妈</option>
						<option value="家长">家长</option>
					</select>
				</div>
				<div class="selectbar clearfix">
					<label for="selectClassName">选择班级(必选)</label> <select
						id="selectClassName" class="chosen">
						<c:forEach var="cls" items="${classList }">
							<option value="${cls.cid}">${cls.cname}</option>
						</c:forEach>
					</select>
				</div>
				<div class="textarea-box clearfix">
					<label for="parentMessage">留言</label>
					<textarea name="parentMessage" id="parentMessage" cols="28"
						rows="7" style="resize:none;"></textarea>
				</div>
			</div>
			<!--  -->
			<div id="formTeacher" style="display:none">
				<div class="inputbar clearfix">
					<label for="tname">教师姓名</label> <input id="tname" name="tname"
						type="text" class="PY-input">
				</div>
				<div class="selectbar clearfix">
					<label for="selectClass">班级(可选)</label> <select name="selectClass"
						id="selectClass" class="chosen">
						<option value="-1">请选择</option>
						<c:forEach var="cls" items="${classList }">
							<option value="${cls.cid}">${cls.cname}</option>
						</c:forEach>
					</select>
				</div>
				<div class="selectbar clearfix">
					<label for="selectJob">职位(可选)</label> <select name="selectJob"
						id="selectJob" class="chosen">
						<option value="-1">请选择</option>
						<c:forEach var="sg" items="${schoolGradeList }">
							<option value="${sg.gid}">${sg.name}</option>
						</c:forEach>
					</select>

				</div>

				<div class="textarea-box clearfix">
					<label for="teacherMessage">留言(必填)</label>
					<textarea name="teacherMessage" id="teacherMessage" cols="28"
						rows="7" style="resize:none;"></textarea>
				</div>


			</div>

		</div>

	</div>



</div>

<script type="text/javascript">
	// 加入学校
	$(".chosen").chosen();
	$('#tabParent').click(function() {
		$('#tabTeacher').removeClass('current');
		$(this).addClass("current");
		$('#formTeacher').css('display', 'none');
		$('#formParent').css('display', 'block');
	});

	$('#tabTeacher').click(function() {
		$('#tabParent').removeClass('current');
		$(this).addClass("current");
		$('#formParent').css('display', 'none');
		$('#formTeacher').css('display', 'block');
	});

	// 获取select列表
	$('#selectJob')
			.click(
					function() {
						function getJobList() {
							//if (data.s == 1) {
							//var jobList = data.jobList;
							//for ( var i=0, i<jobList.length,i++ ) {
							//插入
							//	}

							//	} else {
							// 获取失败
							//}
						}

						exeAjax(
								ajaxUrl("${aier_url}${aier_urijs}schoolclasses_addClass${aier_suffix}"),
								getJobList, {
									"sid" : global_sid
								});
					});

	$("#joinSchool")
			.dialog(
					{
						//背景变暗
						modal : true,
						autoOpen : false,
						show : "fade",
						hide : "fade",
						width : "600",
						height : "470",
						buttons : {
							"确定" : function() {
								if ($('#tabTeacher').hasClass('current')
										&& !$('#tabParent').hasClass('current')) {
									// 获取教师申请内容
									var tname = $('#tname').val().trim();
									var cid = $('#selectClass option:selected')
											.val();
									var gid = $('#selectJob option:selected')
											.val();
									var teacherMessage = $('#teacherMessage')
											.val();
									if (tname == "") {
										$().message("请输入教师姓名");
									} else {
										var funadd = function(data) {
											if (data.s == 1) {
												$().message("申请提交成功!");
												$("#joinSchool")
														.dialog("close");
											} else {
												$()
														.message(
																"申请提交失败! "
																		+ data.error_info);
											}
										};
										exeAjax(
												ajaxUrl("${aier_url}${aier_urijs}schoolhome_addRequest_teacher${aier_suffix}"),
												funadd, {
													"sid" : global_sid,
													"tname" : tname,
													"cid" : cid,
													"gid" : gid,
													"content" : teacherMessage
												});
									}
								} else if (!$('#tabTeacher')
										.hasClass('current')
										&& $('#tabParent').hasClass('current')) {
									// 获取家长申请内容
									var nickname = $('#nickname').val().trim();
									var cid = $(
											'#selectClassName option:selected')
											.val();
									var relation = $(
											'#selectCallName option:selected')
											.val();
									var parentMessage = $('#parentMessage')
											.val();
									if (nickname == "") {
										$().message("请输入宝宝姓名");
									} else {
										var funadd = function(data) {
											if (data.s == 1) {
												$().message("申请提交成功!");
												$("#joinSchool")
														.dialog("close");
											} else {
												$()
														.message(
																"申请提交失败! "
																		+ data.error_info);
											}
										};
										exeAjax(
												ajaxUrl("${aier_url}${aier_urijs}schoolhome_addRequest_parent${aier_suffix}"),
												funadd, {
													"sid" : global_sid,
													"baby_name" : nickname,
													"cid" : cid,
													"relation" : relation,
													"content" : parentMessage
												});
									}
								} else {
									$().message("请刷新本页面后重试");
								}

							},
							"取消" : function() {
								$(this).dialog("close");
							}
						}
					});

	$('.btn-dialog-join').click(function() {
		$("#joinSchool").dialog("open");
	});

	//进入学校后台页面 
	function goschoolM() {
		var fun = function(data) {
			if (data.s == 1) {
				if (data.schoolTeacher.isadmin == 1) {
					window.location.href = "${aier_url}${aier_uri}sbinfo_schoolInfo.shtml?sid="
							+ global_sid + "&tid=" + data.schoolTeacher.tid;
				} else {
					//window.location.href = "${aier_url}${aier_uri}schoolmon_teacherMonAttend.shtml?sid="
					//		+ global_sid + "&tid=" + data.schoolTeacher.tid;
					window.location.href = "${aier_url}${aier_uri}schoolica_teacherIcardInfo.shtml?sid="
	                         + global_sid + "&tid=" + data.schoolTeacher.tid;
				}
			} else {
				$().message("您不是该学校的教师,无权进入");
			}
		};
		exeAjax(
				ajaxUrl("${aier_url}${aier_urijs}schoolhome_isSchoolTeacher${aier_suffix}"),
				fun, {
					"sid" : global_sid
				});
	}

	//上传学校封面

	// 上传文件
	function upfile() {
		var pName = $("#file").val().split("\\")[2];
		if (isnull(pName)) {
			$().message("请选择图片！");
			return;
		}
		var pname1 = pName.substring(pName.lastIndexOf('.')).toLowerCase();
		try {
			$
					.ajaxFileUpload({
						url : "${aier_url}${aier_urijs}scomm_updateSchoolImg${aier_suffix}?sid=${sid}&photoName="
								+ pname1,
						secureuri : false,
						fileElementId : 'file',
						dataType : 'json',
						success : function(data, status) {
							$('#file').hide();
							$('#upPic').hide();
							$('.area-img').show();
							$('#reselect').show();
							$('.area-img').attr("src",
									"${schoolimg_get_url}origin/" + data.img);
							imgName = data.img;
						},
						error : function(data, status, e) {
							$().message("服务器连接超时");
						}
					});
		} catch (e) {
			$().message("服务器连接超时");
		}
		;
	}
	var imgName = "";
	//删除图片
	function delfile() {
		var fun = function(data) {
			if (data.s == 1) {
				$('#file').show();
				$('#upPic').show();
				$('.area-img').hide();
				$('#reselect').hide();

				imgName = "";
			} else {
				$().message("删除失败，请稍后再试！");
			}
		};
		exeAjax(
				ajaxUrl("${aier_url}${aier_urijs}scomm_deleteImage${aier_suffix}"),
				fun, {
					"photoName" : imgName
				});
	}

	$("#file").live('change', function() {
		upfile();
	});

	//读取封面
	function loadCovers() {
		var fun = function(data) {
			if (!isnull(data.img)) {

				$('#top-bg').attr("src",
						"${schoolimg_get_url}origin/" + data.img);
			} else {
				$('#top-bg').attr("src", "${schoolimg_get_url}origin/0.jpg");
			}

		};
		exeAjax(
				ajaxUrl("${aier_url}${aier_urijs}scomm_serachSchoolimg${aier_suffix}"),
				fun, {
					sid : "${sid}"
				});

	}
	loadCovers();
	var selCoId;
	//选定默认封面
	function coLitog(id) {
		for ( var i = 0; i < 4; i++) {
			$("#tha_" + i).removeClass("liborder");
		}
		$("#tha_" + id).addClass("liborder");
		selCoId = id;
	}

	
</script>